package com.yaoxuguang.concurrence.synchronizedpackage.synchronizedCodeBlock;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.synchronizedpackage.synchronizedCodeBlock
 * @Description: 用同步代码块来解决同步方法的弊端
 * @date 2018年12月18日11:12
 */
public class MyTask {
    private String getDetal1;
    private String getDetal2;

    public void doLongTask(){
        try {
            System.out.println("begin task...");
            Thread.sleep(3000);
            String priavteDetal1="长时间处理任务后从远程返回值1 threadName="+Thread.currentThread().getName();
            String priavteDetal2 = "长时间处理任务后从远程返回值2 threadName=" + Thread.currentThread().getName();
            synchronized (this){
                getDetal1 = priavteDetal1;
                getDetal2 = priavteDetal2;
            }
            System.out.println(getDetal1);
            System.out.println(getDetal2);
            System.out.println("end task...");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
